<template>
	<div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>系统参数设置</el-breadcrumb-item>

            </el-breadcrumb>
        </div>
		<div class="container">
            <div class="handle-box">
                <el-button type="warning" icon="el-icon-delete" class="handle-del mr10" @click="delCache" v-loading="cacheLoading">清除配置缓存</el-button>
            </div>
            <el-form :model="form" :rules="rules">
                <el-form-item label="积分兑换比率:">
                    <el-input type="number" min="1" v-model="form.point_rate" style="width: 300px"><template slot="prepend">1元兑换</template><template slot="append">积分</template></el-input>
                </el-form-item>
                <el-form-item label="取消预约限制:">
                    <el-input type="number" min="1" v-model="form.cancel_book_time" style="width: 300px"><template slot="prepend">开课前</template><template slot="append">分钟</template></el-input>
                </el-form-item>
                <el-form-item label="未支付订单失效限制:">
                    <el-input type="number" min="1" v-model="form.invalid_order_time" style="width: 260px"><template slot="append">小时</template></el-input>
                </el-form-item>
                <el-form-item>
                        <el-button type="primary" @click="submitData">提交</el-button>

                </el-form-item>
            </el-form>

		</div>


	</div>
</template>

<script>
	export default {
		name: 'config',
		data() {
			return {
                cacheLoading:false,
				title: '积分兑换比率设置',
                form:{
				    point_rate:1,
                    cancel_book_time:30,
                    invalid_order_time:2,


                }
			}
		},
        created() {
            this.getConfig()
        },
        activated() {
		    this.getConfig()
		},

		methods: {
            delCache(){
                this.cacheLoading = true;
                this.$get(this.$api.delConfigCacheApi).then(res => {
                    this.cacheLoading = false;
                    if (res.code == 200) {
                        this.getConfig();
                        this.$message.success('清除成功！');
                    } else {
                        this.$message.error(res.msg);
                    }
                })

            },
		    getConfig(){
                this.$get(this.$api.configApi, {}).then((res) => {
                    if (res.code == 200) {
                         this.form.point_rate = res.data.point_rate;
                         this.form.cancel_book_time = res.data.cancel_book_time;
                         this.form.invalid_order_time = res.data.invalid_order_time;
                    } else {
                        return this.$message.error(res.msg);
                    }
                });

            },
            submitData(){
		        if(this.form.point_rate===''||this.form.point_rate<1){
		            return this.$message.error('请填写正确的积分兑换比率');
                }
		        let params ={
		            point_rate: this.form.point_rate,
                    cancel_book_time: this.form.cancel_book_time,
                    invalid_order_time: this.form.invalid_order_time,

                }
                this.$post(this.$api.configApi, params).then((res) => {
                    if (res.code == 200) {
                        return this.$message.success('修改成功');
                    } else {
                        return this.$message.error(res.msg);
                        this.getConfig();
                    }
                });

            }
		}
	}
</script>

<style scoped>
	.handle-box {
		margin-bottom: 20px;
		display: flex;
		/* border: 1px solid red; */
	}

	.table {
		width: 100%;
		font-size: 14px;
	}

	/deep/ .isshow .el-upload--picture-card {
		display: none
	}
</style>
